package org.jeecg.modules.param.member.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.param.member.entity.BikeMemberCardLog;
import org.jeecg.modules.param.member.service.IBikeMemberCardLogService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.param.member.vo.*;
import org.jeecg.modules.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 会员卡操作日志表
 * @Author: jeecg-boot
 * @Date:   2021-12-18
 * @Version: V1.0
 */
@Api(tags="会员卡操作日志表")
@RestController
@RequestMapping("/member/bikeMemberCardLog")
@Slf4j
public class BikeMemberCardLogController extends JeecgController<BikeMemberCardLog, IBikeMemberCardLogService> {
	@Autowired
	private IBikeMemberCardLogService bikeMemberCardLogService;

	/**
	 * 分页列表查询
	 *
	 * @param bikeMemberCardLog
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="会员卡操作日志表-分页列表查询", notes="会员卡操作日志表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(BikeMemberCardLog bikeMemberCardLog,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<BikeMemberCardLog> queryWrapper = QueryGenerator.initQueryWrapper(bikeMemberCardLog, req.getParameterMap());
		Page<BikeMemberCardLog> page = new Page<BikeMemberCardLog>(pageNo, pageSize);
		IPage<BikeMemberCardLog> pageList = bikeMemberCardLogService.page(page, queryWrapper);
		return Result.OK(pageList);
	}


	 /**
	  * 会员卡发卡明细
	  *
	  * @param cardDetailRea
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value = "会员卡发卡明细", notes = "会员卡发卡明细")
	 @GetMapping(value = "/toCardDetailList")
	 public Result<?> toCardDetailList(CardDetailReq cardDetailRea,
									   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
									   HttpServletRequest req) {
		 Page<BikeMemberCardLogToRsp> page = new Page<BikeMemberCardLogToRsp>(pageNo, pageSize);
		 cardDetailRea.setOperateType(1);
		 IPage<BikeMemberCardLogToRsp> pageList = bikeMemberCardLogService.toCardDetailList(page, cardDetailRea);
		 return Result.OK(pageList);
	 }

	 /**
	  * 会员卡发卡明细 导出excel
	  *
	  * @param request
	  * @param cardDetailRea
	  */
	 @ApiOperation(value = "会员卡发卡明细 导出excel",produces = "application/octet-stream")
	 @PostMapping(value = "/exportXlsToCardDetail")
	 public ModelAndView exportXlsToCardDetail(HttpServletRequest request, CardDetailReq cardDetailRea) {
		 cardDetailRea.setOperateType(1);
		 List<BikeMemberCardLogToRsp> records = bikeMemberCardLogService.exportXlsToCardDetail(cardDetailRea);
		 return ExcelUtils.exportXls(request,records, BikeMemberCardLogToRsp.class, "会员卡发卡明细");
	 }

	 /**
	  * 会员卡换卡明细
	  *
	  * @param cardDetailRea
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */

	 @ApiOperation(value="会员卡换卡明细", notes="会员卡换卡明细")
	 @GetMapping(value = "/inCardDetailList")
	 public Result<?> inCardDetailList(CardDetailReq cardDetailRea,
									   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									   HttpServletRequest req) {
		 Page<BikeMemberCardLogInRsp> page = new Page<BikeMemberCardLogInRsp>(pageNo, pageSize);
		 cardDetailRea.setOperateType(4);
		 IPage<BikeMemberCardLogInRsp> pageList = bikeMemberCardLogService.inCardDetailList(page, cardDetailRea);
		 return Result.OK(pageList);
	 }
	 /**
	  * 会员卡换卡明细 导出excel
	  *
	  * @param request
	  * @param cardDetailRea
	  */
	 @ApiOperation(value = "会员卡换卡明细 导出excel",produces = "application/octet-stream")
	 @PostMapping(value = "/exportXlsInCardDetail")
	 public ModelAndView exportXlsInCardDetail(HttpServletRequest request, CardDetailReq cardDetailRea) {
		 cardDetailRea.setOperateType(4);
		 List<BikeMemberCardLogInRsp> pageList = bikeMemberCardLogService.exportXlsInCardDetail(cardDetailRea);
		 return ExcelUtils.exportXls(request,pageList, BikeMemberCardLogInRsp.class, "会员卡换卡明细");
	 }
	 /**
	  * 会员卡退卡明细
	  *
	  * @param cardDetailRea
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value="会员卡退卡明细", notes="会员卡退卡明细")
	 @GetMapping(value = "/refundCardDetailList")
	 public Result<?> refundCardDetailList(CardDetailReq cardDetailRea,
									   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									   HttpServletRequest req) {
		 Page<BikeMemberCardLogReturnRsp> page = new Page<BikeMemberCardLogReturnRsp>(pageNo, pageSize);
		 cardDetailRea.setOperateType(5);
		 IPage<BikeMemberCardLogReturnRsp> pageList = bikeMemberCardLogService.refundCardDetailList(page, cardDetailRea);
		 return Result.OK(pageList);
	 }
	 /**
	  * 会员卡退卡明细 导出excel
	  *
	  * @param request
	  * @param cardDetailRea
	  */
	 @ApiOperation(value = "会员卡退卡明细 导出excel",produces = "application/octet-stream")
	 @PostMapping(value = "/exportXlsReturnCardDetail")
	 public ModelAndView exportXlsReturnCardDetail(HttpServletRequest request, CardDetailReq cardDetailRea) {
		 cardDetailRea.setOperateType(5);
		 List<BikeMemberCardLogReturnRsp> pageList = bikeMemberCardLogService.exportXlsReturnCardDetail(cardDetailRea);
		 return ExcelUtils.exportXls(request,pageList, BikeMemberCardLogReturnRsp.class, "会员卡退卡明细");
	 }
	 /**
	  * 会员卡挂失明细
	  *
	  * @param cardDetailRea
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value="会员卡挂失明细", notes="会员卡挂失明细")
	 @GetMapping(value = "/lossCardDetailList")
	 public Result<?> lossCardDetailList(CardDetailReq cardDetailRea,
										   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
										   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
										   HttpServletRequest req) {
		 Page<BikeMemberCardLogLossRsp> page = new Page<BikeMemberCardLogLossRsp>(pageNo, pageSize);
		 IPage<BikeMemberCardLogLossRsp> pageList = bikeMemberCardLogService.lossCardDetailList(page, cardDetailRea);
		 return Result.OK(pageList);
	 }
	 /**
	  * 会员卡解挂失明细 导出excel
	  *
	  * @param request
	  * @param cardDetailRea
	  */
	 @ApiOperation(value = "会员卡解挂失明细 导出excel",produces = "application/octet-stream")
	 @PostMapping(value = "/exportXlsLossCardDetail")
	 public ModelAndView exportXlsLossCardDetail(HttpServletRequest request, CardDetailReq cardDetailRea) {
		 List<BikeMemberCardLogLossRsp> pageList = bikeMemberCardLogService.exportXlsLossCardDetail(cardDetailRea);
		 return ExcelUtils.exportXls(request,pageList, BikeMemberCardLogLossRsp.class, "会员卡解挂失明细");
	 }
	/**
	 *   添加
	 *
	 * @param bikeMemberCardLog
	 * @return
	 */
	@AutoLog(value = "会员卡操作日志表-添加")
	@ApiOperation(value="会员卡操作日志表-添加", notes="会员卡操作日志表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BikeMemberCardLog bikeMemberCardLog) {
		bikeMemberCardLogService.save(bikeMemberCardLog);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param bikeMemberCardLog
	 * @return
	 */
	@AutoLog(value = "会员卡操作日志表-编辑",operateType = 3)
	@ApiOperation(value="会员卡操作日志表-编辑", notes="会员卡操作日志表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BikeMemberCardLog bikeMemberCardLog) {
		bikeMemberCardLogService.updateById(bikeMemberCardLog);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "会员卡操作日志表-通过id删除")
	@ApiOperation(value="会员卡操作日志表-通过id删除", notes="会员卡操作日志表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		bikeMemberCardLogService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "会员卡操作日志表-批量删除")
	@ApiOperation(value="会员卡操作日志表-批量删除", notes="会员卡操作日志表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bikeMemberCardLogService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="会员卡操作日志表-通过id查询", notes="会员卡操作日志表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		BikeMemberCardLog bikeMemberCardLog = bikeMemberCardLogService.getById(id);
		if(bikeMemberCardLog==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bikeMemberCardLog);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param bikeMemberCardLog
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BikeMemberCardLog bikeMemberCardLog) {
        return super.exportXls(request, bikeMemberCardLog, BikeMemberCardLog.class, "会员卡操作日志表");
    }



}
